package cn.wolfcode.shop.controller;

import cn.wolfcode.shop.domain.UserLogin;
import cn.wolfcode.shop.exception.UserException;
import cn.wolfcode.shop.service.IUserLoginService;
import cn.wolfcode.shop.vo.JSONResultVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wolfcode on 2018/8/20.
 */
@RestController
@RequestMapping("/api/users")
public class UserController {
    @Reference
    private IUserLoginService userLoginService;
    @PostMapping
    public JSONResultVo register(String username,String password){
        JSONResultVo vo = new JSONResultVo();
        try{
            UserLogin userLogin = userLoginService.register(username, password);
            vo.setResult(userLogin);
        }catch(UserException e){
            e.printStackTrace();
            vo.setErrorMsg(e.getMessage());
        }
        return vo;
    }
}
